#include "GenThreads.h"

boost::mutex io_mutex;

CGenThreads::CGenThreads(unsigned short dsize):m_verbose(false)
	{
	NUM_CPU=8;
	unsigned  long dlen=((1024l*1024l)/4)*dsize;
	m_data.resize(dlen);
	}

CGenThreads::~CGenThreads(void)
	{
	}

int CGenThreads::parallel_do_RUN(TFunctor* pObj, int istart, int iend, const char *analysistype)
	{

	  /*	  std::cout<<analysistype<<" will run on "<<
	    NUM_CPU<<" threads SIZE="<<m_data.size();	
	  */
	// // Setup a thread group...
	// //
	  {
	    boost::thread_group threads;
	    for(unsigned int i=0;i<NUM_CPU;i++)
	      {
		int dn=int((iend-istart)/float(NUM_CPU))+1;
		int a=istart+i*dn, b=istart+(i+1)*dn;
		if(b>iend)b=iend;
		threads.create_thread(boost::bind(RunInParallel,pObj,a,b, i) );
	      }
	    
	    // Run the thread(s)...
	    threads.join_all();
	  }

	return 0;
	}

